<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class User_Controller extends CI_Controller {

    function __construct() {
        parent::__construct();
    }
    public $table = 'tbl_user';

    public function index() {
        $this->view();
    }

    public function view() {
        $data["title"] = "Users";
        $data['user_list'] = $this->selectModel->selectData($this->table);
        $this->load->view('panel/users/list', $data);
    }

    # to add data
    public function add() {
        $data["title"] = "Users";

        $table_role = "tbl_role";
        $data['role_list'] = $this->selectModel->selectData($table_role);

        if(isset($_POST['save'])){
            $title = $_POST['Title'];
            $fields = array("ProductName", "Enable");
            $values = array($title, 1);
            $data['data_add'] = $this->addModel->addData($this->table, $fields, $values);
            if($data['data_add']){
                $this->session->set_userdata('msg', alert_success('Product add '));
            }else{
                $this->session->set_userdata('msg', alert_error('Product add '));
            }
            redirect('admin_panel/users/view');
        }
        $this->load->view('panel/users/add', $data);
    }

    # to update data
    public function update($val) {
        $field = "ProductID";
        $data["title"] = "Users";
        $data['data_list'] = $this->selectModel->selectDataWhere($this->table, $field, $val);
        if(isset($_POST['update'])){
            echo $val;
            exit;
            $Title = $_POST['Title'];
            $fields = array("ProductName");
            $values = array($Title);
            $data['data_update'] = $this->updateModel->updateData($this->table, $fields, $values, $field, $val);
            if($data['data_update']){
                $this->session->set_userdata('msg', 'You got successful!!');
            }else{
                $this->session->set_userdata('msg', 'You are fail!!');
            }
            redirect('admin_panel/product/view');
        }
        $this->load->view('panel/product/edit', $data);
    }

    # to delete data
    public function delete($val) {
        #code here
        $field = "Enable";
        $val = 0;
        $data['delete'] = $this->deleteModel->deleteData($this->table, $field, $val);
        if($data['delete']){
            $this->session->set_userdata('msg', 'You got successful!!');
        }else{
            $this->session->set_userdata('msg', 'You are fail!!');
        }
        redirect('admin_panel/product/view');
    }
}

/* End of file user_controller.php */
/* Location: ./application/controllers/panel/user_controller.php */